﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BaseEntityApi;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Windows;
using System.Windows.Controls;

namespace WPF_MVVMDemo
{
    public class MainWindowModel : ViewModelBase
    {
        //绑定 listview　combox 
        private ObservableCollection<TestTempData> _TemDataList;
        public ObservableCollection<TestTempData> TemDataList
        {
            get { return _TemDataList; }
        }
        public MainWindowModel()
        {
            _TemDataList = new ObservableCollection<TestTempData>();
            _TemDataList = new ObservableCollection<TestTempData>(ComSubHelpr.GetData());
            _TemDataItem = _SelectedData = _TemDataList[0];//默认选中第一项
        }

        private int _selectindex = 0;
        public int selectIndex { get { return _selectindex; } set { _selectindex = value; } }
        //textbox2
        private TestTempData _TemDataItem;
        public TestTempData TemDataItem
        {
            get { return _TemDataItem; }
            set
            {
                _TemDataItem = value;
                OnPropertyChanged("TemDataItem");
            }
        }
        //textBox
        private string _textTem;
        public string textTem
        {
            get { return _textTem; }
            set { _textTem = value; OnPropertyChanged("textTem"); }
        }

        //绑定的button Click 事件
        private CommandBase _ButtonClikCommand;
        public ICommand ButtonClikCommand
        {
            get
            {
                if (_ButtonClikCommand == null)
                {
                    _ButtonClikCommand = new CommandBase(o => this.ButtonClick());
                }
                return _ButtonClikCommand;
            }
        }
        private void ButtonClick()
        {
            string tem = textTem.Trim();
            if (tem == string.Empty || tem == null)
            {
                MessageBox.Show("有问题了！");
                //throw new Exception("有问题了！");
            }
            this.TemDataList.Add(new TestTempData { Title = tem });
        }

        //绑定Combox
        private TestTempData _SelectedData;
        public TestTempData SelectedData
        {
            get { return _SelectedData; }
            set
            {
                _SelectedData = value;
                textTem = _SelectedData.Title;
                DolvSelectChanged(_SelectedData);//执行切换动作
                OnPropertyChanged("SelectedData");
            }
        }
        public void DolvSelectChanged(object sender)
        {

        }
    }

}
